package com.gmall.search.controller;

import com.gmall.common.result.Result;
import com.gmall.search.service.IndexService;
import com.gmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.ParseException;
import java.util.Map;

@RestController
@RequestMapping("/api/search")
public class SearchController {

    @Autowired
    IndexService indexService;

    @Autowired
    SearchService searchService;

    @PostMapping("{page}/{size}")
    public Result<Map> search(@PathVariable Integer page,
                      @PathVariable Integer size,
                      @RequestBody Map searchMap) throws IOException, ParseException {
        return searchService.search(page,size,searchMap);
    }
    /**
     * 创建索引和mapping
     *
     * @return
     */
    @GetMapping("/inner/createIndex")
    public Result createIndex() {
        return indexService.createIndex();
    }
}
